sysroot: Cache an OstreeRepo instance
authorMatthew Barnes <mbarnes@redhat.com>
Fri, 17 Apr 2015 13:00:17 +0000 (09:00 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 17 Apr 2015 15:19:08 +0000 (11:19 -0400)
Rather than returning a new OstreeRepo instance in each call to
ostree_sysroot_get_repo(), cache one internally so the same instance
is returned each time.

src/libostree/ostree-sysroot-private.h
src/libostree/ostree-sysroot.c

index 03224dec9485537b274a2c7d82f2d26a8d78cb04..69310c3f6eec7d66c57a6ce697729237846ccaab 100644 (file)
@@ -40,6 +40,9 @@ struct OstreeSysroot {
   int bootversion;
   int subbootversion;
   OstreeDeployment *booted_deployment;
+
+  /* Only access through ostree_sysroot_get_repo() */
+  OstreeRepo *repo;
 };
 
 gboolean
index 2afc59c3535b23c466ec4d8a3f3937643a9c8b4b..6d622402dbb3d1772ad3ec5ae548ef8423ab4f5e 100644 (file)
@@ -64,6 +64,7 @@ ostree_sysroot_finalize (GObject *object)
 
   g_clear_object (&self->path);
   g_clear_object (&self->sepolicy);
+  g_clear_object (&self->repo);
 
   G_OBJECT_CLASS (ostree_sysroot_parent_class)->finalize (object);
 }
@@ -111,9 +112,13 @@ static void
 ostree_sysroot_constructed (GObject *object)
 {
   OstreeSysroot *self = OSTREE_SYSROOT (object);
+  gs_unref_object GFile *repo_path = NULL;
 
   g_assert (self->path != NULL);
 
+  repo_path = g_file_resolve_relative_path (self->path, "ostree/repo");
+  self->repo = ostree_repo_new (repo_path);
+
   G_OBJECT_CLASS (ostree_sysroot_parent_class)->constructed (object);
 }
 
@@ -875,15 +880,15 @@ ostree_sysroot_get_repo (OstreeSysroot         *self,
                          GError       **error)
 {
   gboolean ret = FALSE;
-  gs_unref_object OstreeRepo *ret_repo = NULL;
-  gs_unref_object GFile *repo_path = g_file_resolve_relative_path (self->path, "ostree/repo");
 
-  ret_repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_open (ret_repo, cancellable, error))
+  /* ostree_repo_open() is idempotent. */
+  if (!ostree_repo_open (self->repo, cancellable, error))
     goto out;
-    
+
+  if (out_repo != NULL)
+    *out_repo = g_object_ref (self->repo);
+
   ret = TRUE;
-  ot_transfer_out_value (out_repo, &ret_repo);
  out:
   return ret;
 }